<div class="boxed">
    <div id="content-container">
        <div id="page-title">
            <h1 class="page-header text-overflow">Data Tables</h1>
            <div class="searchbox">
                <div class="input-group custom-search-form">
                    <input type="text" class="form-control" placeholder="Search..">
                    <span class="input-group-btn">
                        <button class="text-muted" type="button"><i class="demo-pli-magnifi-glass"></i></button>
                    </span>
                </div>
            </div>
        </div>
        <ol class="breadcrumb">
            <li><a href="{:url('Admin/Index/index')}">首页</a></li>
            <li><a href="#">权限控制</a></li>
            <li class="active">角色列表</li>
        </ol>
        <div class="panel">
            <div class="panel-body">
                <div class="pad-btm form-inline">
                    <div class="row">
                        <div class="col-sm-6 table-toolbar-left">
                            <button id="demo-btn-addrow" class="btn btn-mint" onclick="add()">新增角色</button>
                        </div>
                    </div>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>分组名</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="data" id="v"}
                        <tr>
                            <td>{$v['title']}</td>
                            <td>
                                <a href="javascript:;" ruleId="{$v['id']}" ruleTitle="{$v['title']}" onclick="edit(this)">修改</a> |
                                <a href="javascript:if(confirm('确定删除？'))location='{:url('Admin/Rule/delete_group',array('id'=>$v['id']))}'">删除</a> |
                                <a href="{:url('Admin/Rule/rule_distribution',array('id'=>$v['id']))}">分配权限</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 添加菜单模态框开始 -->
<template id="thinkright-add">
    <div class="modal-dialog" style="margin-bottom:0">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    新增角色
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" action="{:url('Admin/Rule/add_group')}" method="post">
                    <div class="form-group">
                        <label for="demo-inline-inputmail" class="sr-only">角色名：</label>
                        <input type="text" placeholder="请输入角色"  id="demo-inline-inputmail" class="form-control" name="title" required="required">
                    </div>
                    <button class="btn btn-primary" type="submit">添加</button>
                </form>

            </div>
        </div>
    </div>
</template>
<!-- 添加菜单模态框结束 -->

<!-- 修改菜单模态框开始 -->
<template id="thinkright-edit">
    <div class="modal-dialog" style="margin-bottom:0">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改规则
                </h4>
            </div>
            <div class="modal-body">
                <form id="bjy-form" class="form-inline" action="{:url('Admin/Rule/edit_group')}" method="post">
                    <input type="hidden" name="id">
                    <div class="form-group">
                        <label for="demo-inline-inputmail" class="sr-only">角色名：</label>
                        <input type="text" placeholder="请输入角色"  id="demo-inline-inputmail" class="form-control" name="title" required="required">
                    </div>
                    <button class="btn btn-primary" type="submit">修改</button>
                </form>
            </div>
        </div>
    </div>
</template>
<!-- 修改菜单模态框结束 -->

<!-- 给角色添加用户开始 -->
<div class="modal fade" id="thinkright-adduser" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加成员
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-inline" action="{:url('Admin/Rule/add_user')}" method="post">
                    <div class="form-group">
                        <label for="demo-inline-inputmail" class="sr-only">成员名：</label>
                        <input type="text" placeholder="请输入角色的成员"  id="demo-inline-inputmail" class="form-control" name="title" required="required">
                        <input type="hidden" name="group_id">
                    </div>
                    <button class="btn btn-primary" type="submit">添加</button>
                </form>

            </div>
        </div>
    </div>
</div>
<!-- 给角色添加用户结束 -->

<script>
    function showTips(name,width,height) {
        layer.open({
            type: 1,
            shade: 0.6,
            title: false, //不显示标题
            area: [width+'px', height+'px'], //宽高
            scrollbar: false,
            content:$(name).html(),
            cancel: function(){}
        });
    }
    // 添加菜单
    function add(){
        $("input[name='title']").val('');
        showTips('#thinkright-add',600,140)
    }
    // 修改菜单
    function edit(obj){
        var ruleId=$(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        showTips('#thinkright-edit',600,140);
        setTimeout(function () {
            $("input[name='id']").val(ruleId);
            $("input[name='title']").val(ruletitle);
        },200)
    }

    // 向角色添加用户 Admin/Rule/check_user
    function adduser(obj){
        var groupId=$(obj).attr('groupId');
        // var ruletitle=$(obj).attr('ruletitle');
        $("input[name='group_id']").val(groupId);
        // $("input[name='title']").val(ruletitle);
        $('#thinkright-adduser').modal('show');
    }
</script>
